<!DOCTYPE html>
<html lang="en">
<head xmlns:th="http://www.thymeleaf.org">
    <meta charset="UTF-8">
    <title>重庆工商大学成绩管理系统</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <script src="/js/jquery.js"></script>
    <link rel="stylesheet" href="/plugins/bootstraptable/bootstrap-table.min.css">
    <link href="/img/ctbulogo.jpg" rel="icon" ,type="image/x-icon">
    <style>
        .container-fluid{
            display: flex;
            justify-content: center;
        }
    </style>
</head>
<body background="/img/login.png">
<div class="container-fluid"  >
    <div class="panel panel-default"  style="height: 450px;width: 700px;" >
        <div class="panel-heading" style="font-size:40px;color: #1b5fcc;font-family:华文楷体;font-weight: 700"><img src="/img/ctbulogo.jpg" height="100" width="100"/>重庆工商大学统一身份认证</div>
        <div class="panel-body" style="font-size:25px;color: #0a0a0a;font-family:华文楷体;font-weight: 500">
            <form>
                <div class="form-group">
                    <label for="username">帐号</label>
                    <input type="text" class="form-control" id="username" name="username" placeholder="工号/学号">
                </div>
                <div class="form-group">
                    <label for="password">密码</label>
                    <input type="password" class="form-control" id="password"  name="password" placeholder="Password">
                </div>
                <label for="options">角色</label>
                <select class="form-control" id="options" name="options">
                    <option>管理员</option>
                    <option>老师</option>
                    <option>学生</option>
                </select>
                <button type="button" class="btn btn-primary" onclick="login();" >认证</button>
            </form>
        </div>

    </div>
</div>
<script type="text/javascript">
    function login(){
        var name=$("#username").val();
        var password=$("#password").val();
        var position=$("#options").val();
        if(position=="管理员"){
            $.ajax({
                url:"/webapi/login/admin",
                data:{
                    ano:name,
                    password:password
                }
            }).done(function (rs){
                if (rs>=0){
                    //成功
                    window.location.href="/admin/admininfo";
                }
                else{
                    alert("认证失败，请检查账号密码和角色权限是否正确！");
                }
            })

        }else if(position=="老师"){
            $.ajax({
                url:"/webapi/login/teacher",
                data:{
                    tno:name,
                    password:password
                }
            }).done(function (rs){
                if (rs>=0){
                    //成功
                    window.location.href="/teacher/teacherinfo";
                }
                else{
                    alert("认证失败，请检查账号密码和角色权限是否正确！");
                }
            })
        }else{
            $.ajax({
                url:"/webapi/login/student",
                data:{
                    sno:name,
                    password:password
                }
            }).done(function (rs){
                if (rs>=0){
                    //成功
                    window.location.href="/student/studentinfo";
                }
                else{
                    alert("认证失败，请检查账号密码和角色权限是否正确！");
                }
            })
        }
    }
</script>
</body>
</html>